<template>
  <div class="company-style">
    <!-- 导航栏 start -->
    <NavBarVue :title="title" />
    <!-- 导航栏 end -->

    <!-- 内容 -->
    <div class="content-top">
      <MyEmpty v-if="isLoading === false && list.length === 0" />
      <van-list
        class="my-resume-list"
        v-model="isLoading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        v-else
      >
        <van-swipe-cell class="item" v-for="(item, index) in list" :key="index">
          <div class="show" @click="toViewResume(item.resumeid, 0)">
            <div class="person">
              <img :src="item.logo" alt="" v-if="item.logo != ''" />
              <template v-else>
                <img
                  src="@/assets/img/my/no-avatar-boy.png"
                  alt=""
                  v-if="item.sex === '男'"
                />
                <img src="@/assets/img/my/no-avatar-girl.png" alt="" v-else />
              </template>
              <p>
                <b>{{ item.name }}</b>
                <span>{{ item.showDate }}</span>
              </p>
              <p>
                <span>{{ item.sex }}</span>
                <span>{{ item.age }}岁</span>
                <span>{{ item.edu }}</span>
                <span>{{ item.workyear }}</span>
              </p>
            </div>
          </div>
          <template #right>
            <van-button
              square
              text="删除"
              type="danger"
              style="height: 100%"
              @click="onDel(item, index)"
            />
          </template>
        </van-swipe-cell>
      </van-list>
    </div>
  </div>
</template>

<script>
import NavBarVue from "@/components/NavBar.vue";
import MyEmpty from "@/components/MyEmpty.vue";
import { List, Button, SwipeCell, Toast, Dialog } from "vant";
import { CompanyResumeGetCollect, CompanyResumeDelCollect } from "@/util/http";
import { mixin_company_common } from "@/mixin/mixins";
export default {
  name: "CollectResume",
  components: {
    NavBarVue,
    MyEmpty,
    [List.name]: List,
    [Button.name]: Button,
    [SwipeCell.name]: SwipeCell,
  },
  props: ["title"],
  mixins: [mixin_company_common],
  mounted() {
    this.onLoad();
  },
  // 定义属性
  data() {
    return {
      list: [],
      page: 0,
      finished: false,
      isLoading: false,
    };
  },
  // 方法集合
  methods: {
    onLoad() {
      let page = this.page;
      page++;
      this.page = page;

      this.isLoading = true;
      CompanyResumeGetCollect(page).then((res) => {
        // console.log(res);
        this.isLoading = false;
        let list = res.list;
        if (list.length > 0) {
          this.list = [...this.list, ...list];
          this.finished = false;
        } else {
          this.finished = true;
        }
      });
    },
    onDel(item, index) {
      Dialog.confirm({
        message: "确认删除该简历？",
        confirmButtonText: "删除",
      })
        .then(() => {
          CompanyResumeDelCollect(item.id).then((res) => {
            Toast(res.msg);
            if (res.result === 1) {
              this.list.splice(index, 1);
            }
          });
        })
        .catch(() => {
          // on cancel
        });
    },
  },
};
</script>

<style lang="less">
@import "vant/lib/index.less";
@import "@/assets/css/company.less";
</style>
